In [4]:
%load_ext autoreload
%autoreload 2
In [5]:
from pearce.emulator import OriginalRecipe, ExtraCrispy
from pearce.mocks import cat_dict
import numpy as np
from os import path
In [6]:
import matplotlib
#matplotlib.use('Agg')
from matplotlib import pyplot as plt
%matplotlib inline
import seaborn as sns
sns.set()
In [7]:
training_file = '/u/ki/swmclau2/des/PearceRedMagicXiChinchilla.hdf5'
em_method = 'nn'
split_method = 'random'
In [8]:
a = 1.0
z = 1.0/a - 1.0
In [ ]:
fixed_params = {'z':z}
In [ ]:
emu = OriginalRecipe(training_file, method = em_method, fixed_params=fixed_params,
hyperparams = {'hidden_layer_sizes': (50, 25),
'activation': 'relu', 'verbose': False,
'tol': 1e-8, 'learning_rate_init':1e-6,\
'max_iter':5000, 'alpha':0, 'early_stopping':False, 'validation_fraction':0.3})
In [ ]:
np.abs(emu.goodness_of_fit(training_file, statistic = 'log_frac')).mean()
In [ ]:
np.abs(emu.goodness_of_fit(training_file, statistic = 'frac')).mean()
In [ ]:
fit_idxs = np.argsort(gof.mean(axis = 1))
In [ ]:
emu.goodness_of_fit(training_file).mean()#, statistic = 'log_frac')).mean()
In [ ]:
model = emu._emulator
In [ ]:
ypred = model.predict(emu.x)
In [ ]:
plt.hist( np.log10( (emu._y_std+1e-5)*np.abs(ypred-emu.y)/np.abs((emu._y_std+1e-5)*emu.y+emu._y_mean) ))
In [ ]:
( (emu._y_std+1e-5)*np.abs(ypred-emu.y)/np.abs((emu._y_std+1e-5)*emu.y+emu._y_mean) ).mean()
In [ ]:
emu._y_mean, emu._y_std
In [ ]:
for idx in fit_idxs[:10]:
print gof[idx].mean()
print (ypred[idx*emu.n_bins:(idx+1)*emu.n_bins]-emu.y[idx*emu.n_bins:(idx+1)*emu.n_bins])/emu.y[idx*emu.n_bins:(idx+1)*emu.n_bins]
plt.plot(emu.scale_bin_centers, ypred[idx*emu.n_bins:(idx+1)*emu.n_bins], label = 'Emu')
plt.plot(emu.scale_bin_centers, emu.y[idx*emu.n_bins:(idx+1)*emu.n_bins], label = 'True')
plt.legend(loc='best')
plt.xscale('log')
plt.show()
In [ ]:
print dict(zip(emu.get_param_names(), emu.x[8*emu.n_bins, :]*emu._x_std+emu._x_mean))
In [ ]:
emu.get_param_names()
In [ ]:
emu._ordered_params
In [ ]:
gof = emu.goodness_of_fit(training_file, statistic = 'frac')
print gof.mean()
In [ ]:
for row in gof:
print row
In [ ]:
gof = emu.goodness_of_fit(training_file, statistic = 'frac')
print gof.mean()
In [ ]:
model = emu._emulator
In [ ]:
model.score(emu.x, emu.y)
In [ ]:
ypred = model.predict(emu.x)
np.mean(np.abs(ypred-emu.y)/emu.y)
In [ ]:
plt.plot(emu.scale_bin_centers, np.abs(gof.mean(axis = 0)) )
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.01)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.05)
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.1)
plt.loglog();
In [ ]:
plt.plot(emu.scale_bin_centers, np.abs(gof.T),alpha = 0.1, color = 'b')
plt.plot(emu.scale_bin_centers, np.ones_like(emu.scale_bin_centers)*0.01, lw = 2, color = 'k')
plt.loglog();
In [ ]:
gof[:,i].shape
In [ ]:
for i in xrange(gof.shape[1]):
plt.hist(np.log10(gof[:, i]), label = str(i), alpha = 0.2);
plt.legend(loc='best')
plt.show()
In [ ]: